package net.web.milkteapos;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;

import net.web.milkteapos.bean.Employee;
import net.web.milkteapos.bean.Product;
import net.web.milkteapos.bean.ProductType;
import net.web.milkteapos.bean.User;


public class MainSetup implements Setup {
	
	public void init(NutConfig conf) {
        Ioc ioc = conf.getIoc();
        Dao dao = ioc.get(Dao.class);
        
        
        Daos.createTablesInPackage(dao, "net.web.milkteapos", false);

        if (dao.count(ProductType.class) == 0) {
			ProductType type = new ProductType();
			type.setTypeId(1);
			type.setTypeName("珍珠奶茶");
			dao.insert(type);
			ProductType type2 = new ProductType();
			type2.setTypeId(2);
			type2.setTypeName("红豆奶茶");
			dao.insert(type2);
			ProductType type3 = new ProductType();
			type3.setTypeId(3);
			type3.setTypeName("绿豆奶茶");
			dao.insert(type3);
        }

        if (dao.count(Employee.class) == 0) {
        	Employee employee = new Employee();
        	employee.setName("服务员A");
        	dao.insert(employee);
        }
        
        
//        Ioc ioc = conf.getIoc();
//        Dao dao = ioc.get(Dao.class);
        Daos.createTablesInPackage(dao, "net.wendal.nutzbook", false);
		
        if (dao.count(User.class) == 0) {
            User user = new User();
            user.setName("admin");
            user.setPassword("123456");
            user.setCreateTime(new Date());
            user.setUpdateTime(new Date());
            dao.insert(user);
        }
        
        
        
        
    }

    public void destroy(NutConfig conf) {
    }
}
